package com.ssm.controller;

import com.ssm.common.Result;
import com.ssm.entity.Product;
import com.ssm.service.ProductService;
import com.ssm.vo.SearchCriteriaVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@RestController
@RequestMapping("/api/product")
class ProductColl {

    @Autowired
    ProductService productService;

    /**
     * 商品分页查询;
     * @param pageNum 从第几条数据开始查;
     * @param pageSize 查几条数据;
     * @return 返回商品集合;
     */
    @GetMapping("/byPage/{pageNum}/{pageSize}")
    public Result ProductByPage(
            @PathVariable( "pageNum") Integer pageNum,
            @PathVariable("pageSize") Integer pageSize
    ){
        List<Product> productList= productService.ProductByPage(pageNum,pageSize);

        for (Product product : productList) {
            String old = product.getSkuPhoto();
            String newString = "http://10.5.50.177:8080/images/"+old;
            product.setSkuPhoto(newString);
        }
        return Result.success("分页成功",productList);
    }

    /**
    * 模糊查询商品;
    * @return  商品的集合;
     */
    @GetMapping("/ByCriteriaSearchVo")
    public Result<List<Product>> ByCriteriaSearchVo(
            SearchCriteriaVo searchCriteriaVo
    ){
        List<Product> productList= productService.ByCriteriaSearchVo(searchCriteriaVo);
        for (Product product : productList) {
            String old = product.getSkuPhoto();
            String newString = "http://10.5.50.177:8080/images/"+old;
            product.setSkuPhoto(newString);
        }
        return Result.success("查找成功",productList);
    }
}
